import { actions } from "../../http/actions";
import { hc } from "../../hc";
import HCMqttBaseService from "../BaseService";

export default class HCMQTTSystemService extends HCMqttBaseService {

	/**
	 * 获取软件版本信息
	 *
	 */
	async getSystemVersions(topic: string) {
		const operator = actions.Versions;
		const data = { operator, info: {} };
		const client = this.getMQTTClient();
		const res = await client.fetch<hc.mqtt.GetVersionsAck>(topic, data);
		return res;
	}

	/** 更新设备固件程序版本
	 * @param {string} name 版本名称 必填
	 * @param {string} path 文件url，必须是海清swx结尾的http链接 e.g. http://a.com/b/c/xxxxxxxxx.swx
	 *
	 */
	async upgradeSWX(topic: string, name: string, path: string) {
		const operator = actions.Upgrade;
		const data = {
			operator,
			info: {
				name: name,
				upgradeType: 1,
				path,
			},
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.GetVersionsAck>(topic, data);
		return res;
	}

	/** 更新设备语音
	 * @param {string} path 语音文件url，必须是海清设备已有的声音文件名称结尾的http链接 e.g. http://a.com/b/c/Welcome.wav
	 *
	 */
	async upgradeAudio(topic: string, path: string) {
		const operator = actions.Upgrade;
		const data = {
			operator,
			info: {
				name: "1",
				upgradeType: 2,
				path,
			},
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.GetVersionsAck>(topic, data);
		return res;
	}

	/** 更新设备公司logo
	 * @param {string} path 图片文件url，必须以固定文件名结尾：e.g. http:/a.com/b/c/CompanyLogo.png
	 *
	 */
	async upgradeCompanyLogo(topic: string, path: string) {
		const operator = actions.Upgrade;
		const data = {
			operator,
			info: {
				name: "1",
				upgradeType: 3,
				path,
			},
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.GetVersionsAck>(topic, data);
		return res;
	}

	/** 更新设备背景图片
	 * @param {string} path 背景文件png，大小必须：800:1280   e.g. http:/a.com/b/c/x.png
	 *
	 */
	async upgradeBackgroundImg(topic: string, path: string) {
		const operator = actions.Upgrade;
		const data = {
			operator,
			info: {
				name: "1",
				upgradeType: 3,
				path,
			},
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.GetVersionsAck>(topic, data);
		return res;
	}
}
